<?php

namespace lico\MVC;

use lico\Runtime\Request;
use lico\Runtime\Response;
use lico\Runtime\Route;

class Controller
{

    protected $_request;
    protected $_response;
    

    public function __construct(Request $request,Response $response)
    {
        $this->_request = $request;
        $this->_response = $response;
    }

    /**
     * 获取所有参数
     */
    protected function params()
    {
        return $this->_request->params();
    }

    /**
     * json数据显示
     */
    protected function jsonView($msg, $data, $code = 0)
    {
        $this->_response->setDataType('json');
        $this->_response->setData(json_encode([
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ]));
        echo $this->_response->getData();
    }

    /**
     * smarty绑定数据
     */
    protected function assign($key, $data)
    {
        $this->_response->setData($key, $data);
    }

    /**
     * smarty渲染
     */
    protected function display($html = "")
    {
        $this->_response->setDataType('html');
        if (!$html) {
            $html = \lico\Container::getBowl('lico\Runtime\Route')->method();
        }
        return $this->_response->view($html);
    }
}
